package edu.kit.csl.tests.pisa.datatypes;

/*
This file is part of the PISA Alignment Tool.

Copyright (C) 2013
Karlsruhe Institute of Technology
Cognitive Systems Lab (CSL)
Felix Stahlberg

PISA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PISA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PISA. If not, see <http://www.gnu.org/licenses/>.
*/

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import edu.kit.csl.pisa.datatypes.Dictionary;

/**
 * Testing class for {@link edu.kit.csl.pisa.datatypes.Dictionary}.
 */
public class DictionaryTest {

	static protected Dictionary dict;
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		dict = Dictionary.getSingleton(Dictionary.TRGT_DICT);
		dict.clear();
	}

	/**
	 * Test method for {@link edu.kit.csl.pisa.datatypes.Dictionary#getSingleton(int)}.
	 */
	@Test
	public final void testGetSingleton() {
		Assert.assertNotNull(Dictionary.getSingleton(Dictionary.SRC_DICT));
		Assert.assertNotNull(Dictionary.getSingleton(Dictionary.TRGT_DICT));
		Assert.assertNull(Dictionary.getSingleton(-1));
	}

	/**
	 * Test method for {@link edu.kit.csl.pisa.datatypes.Dictionary#get(java.lang.String)}.
	 */
	@Test
	public final void testGetString() {
		Assert.assertEquals(0, Dictionary.getSingleton(Dictionary.SRC_DICT)
				.get("NULL"));
		Assert.assertEquals(0, dict.get("word0"));
		Assert.assertEquals(1, dict.get("word1"));
		Assert.assertEquals(0, dict.get("word0"));
	}

	/**
	 * Test method for {@link edu.kit.csl.pisa.datatypes.Dictionary#get(int)}.
	 */
	@Test
	public final void testGetInt() {
		Assert.assertEquals("NULL", Dictionary.getSingleton(Dictionary.SRC_DICT)
				.get(0));
		Assert.assertEquals(0, dict.get("word0"));
		Assert.assertEquals(1, dict.get("word1"));
		Assert.assertEquals("word0", dict.get(0));
		Assert.assertEquals("word1", dict.get(1));
	}

	/**
	 * Test method for {@link edu.kit.csl.pisa.datatypes.Dictionary#size()} and
	 * {@link edu.kit.csl.pisa.datatypes.Dictionary#clear()}
	 */
	@Test
	public final void testSizeAndClear() {
		Assert.assertEquals(0, dict.size());
		dict.get("word0");
		dict.get("word1");
		Assert.assertEquals(2, dict.size());
		dict.get("word0");
		Assert.assertEquals(2, dict.size());
		dict.clear();
		Assert.assertEquals(0, dict.size());
	}
}
